<?php

namespace Kangcg\Application\Base;

use ArrayAccess;

class ObjectAssistance implements ArrayAccess
{
    protected array $_config = [];

    /**
     * 设置初始配置信息!
     * @param array $config
     * @return $this
     */
    public function setConfig(array $config = [])
    {
        foreach ($config as $attr => $value) {
            $this->{$attr} = $value;
        }

        return $this;
    }

    /**
     * 获取配置信息
     * @return array
     */
    public function getConfig(): array
    {
        return $this->_config;
    }

    public function offsetSet($offset, $value): void
    {
        $this->_config[$offset] = $value;
    }

    public function offsetExists($offset): bool
    {
        return isset($this->_Config[$offset]);
    }

    public function offsetUnset($offset): void
    {
        unset($this->_config[$offset]);
    }

    public function offsetGet($offset): mixed
    {
        return $this->_config[$offset] ?? null;
    }
}
